package com.example.administrator.ygddriver.tool;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.Toolbar;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.administrator.ygddriver.R;


public class SimpleToolbar extends Toolbar {


    /**
     * 中间Title
     */
    private TextView mTxtMiddleTitle;

    /**
     * 返回图片
     */
    private ImageView backIv;
    /**
     * 结尾图片
     */
    private ImageView endIv;

    /**
     * 结尾文字
     */
    private TextView mTxtEndTv;

    /**
     * 开始文字
     */
    private TextView backTv;


    private Toolbar toolbar;

    public SimpleToolbar(Context context) {
        this(context, null);
    }

    public SimpleToolbar(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SimpleToolbar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
       LayoutInflater.from(context).inflate(R.layout.txt_simple_toolbar, this);
        toolbar = findViewById(R.id.txt_simple_toolbar);
//        mTxtLeftTitle = (TextView) findViewById(R.id.txt_left_title);
        mTxtMiddleTitle = findViewById(R.id.txt_simple_toolbar_title_tv);
//        mTxtRightTitle = (TextView) findViewById(R.id.txt_right_title);
        backIv = findViewById(R.id.txt_simple_toolbar_back_iv);
        endIv = findViewById(R.id.txt_simple_toolbar_end_iv);
        mTxtEndTv = findViewById(R.id.txt_simple_toolbar_end_tv);
        backTv = findViewById(R.id.txt_simple_toolbar_back_tv);
    }

    //设置中间title的内容
    public void setMainTitle(String text) {
        this.setTitle(" ");
        mTxtMiddleTitle.setVisibility(View.VISIBLE);
        mTxtMiddleTitle.setText(text);
    }

    //设置中间title的内容文字的颜色
    public void setMainTitleColor(String color) {
        mTxtMiddleTitle.setTextColor(Color.parseColor(color));
    }

    //设置开始文字内容
    public void setBackTv(String text) {
        this.setTitle(" ");
        backTv.setVisibility(View.VISIBLE);
        backTv.setText(text);
    }

    //设置开始的文字的颜色
    public void setBackTvColor(String color) {
        backTv.setTextColor(Color.parseColor(color));
    }

    //设置左边图片
    public void setBackIv(int id) {
        backIv.setImageResource(id);
        backIv.setVisibility(VISIBLE);
    }

    //设置结尾图片
    public void setEndIv(int id) {
        endIv.setImageResource(id);
        endIv.setVisibility(VISIBLE);
    }

    //设置结尾文字
    public void setEndTv(String text) {
        this.setTitle(" ");
        mTxtEndTv.setVisibility(View.VISIBLE);
        mTxtEndTv.setText(text);
    }
    //设置开始的文字的颜色
    public void setEndTvColor(String color) {
        mTxtEndTv.setTextColor(Color.parseColor(color));
    }

    //设置tool颜色
    public void setToolColor(String color) {
        toolbar.setBackgroundColor(Color.parseColor(color));
    }

    //设置左面图片点击事件
    public void setBackIvClickListener(OnClickListener onClickListener) {
        backIv.setOnClickListener(onClickListener);
    }

    //设置结尾图片点击事件
    public void setEndIvClickListener(OnClickListener onClickListener) {
        endIv.setOnClickListener(onClickListener);
    }

    //设置标题点击事件
    public void setTitleTvClickListener(OnClickListener onClickListener) {
        mTxtMiddleTitle.setOnClickListener(onClickListener);
    }

    //设置结尾文字点击事件
    public void setEndTvClickListener(OnClickListener onClickListener) {
        mTxtEndTv.setOnClickListener(onClickListener);
    }
    //设置开始文字点击事件
    public void setBackTvClickListener(OnClickListener onClickListener) {
        backTv.setOnClickListener(onClickListener);
    }

    //设置title左边文字
    public void setLeftTitleText(String text) {

    }

    //设置title左边文字颜色
    public void setLeftTitleColor(int color) {

    }

    //设置title左边图标
    public void setLeftTitleDrawable(int res) {
        Drawable dwLeft = ContextCompat.getDrawable(getContext(), res);
        dwLeft.setBounds(0, 0, dwLeft.getMinimumWidth(), dwLeft.getMinimumHeight());
//        mTxtLeftTitle.setCompoundDrawables(dwLeft, null, null, null);
    }

    //设置title左边点击事件
    public void setLeftTitleClickListener(OnClickListener onClickListener) {
//        mTxtLeftTitle.setOnClickListener(onClickListener);
    }

    //设置title右边文字
    public void setRightTitleText(String text) {
//        mTxtRightTitle.setVisibility(View.VISIBLE);
//        mTxtRightTitle.setText(text);
    }

    //设置title右边文字颜色
    public void setRightTitleColor(int color) {
//        mTxtRightTitle.setTextColor(color);
    }

    //设置title右边图标
    public void setRightTitleDrawable(int res) {
        Drawable dwRight = ContextCompat.getDrawable(getContext(), res);
        dwRight.setBounds(0, 0, dwRight.getMinimumWidth(), dwRight.getMinimumHeight());
//        mTxtRightTitle.setCompoundDrawables(null, null, dwRight, null);
    }

    //设置title右边点击事件
    public void setRightTitleClickListener(OnClickListener onClickListener) {
//        mTxtRightTitle.setOnClickListener(onClickListener);
    }

    @Override
    public void setBackground(Drawable background) {
        super.setBackground(background);
    }
}

